package com.along.utility.common.response;

import com.github.pagehelper.Page;

import java.util.List;

/**
 *
 * @author jingjiwu
 * @date 2021-01-11 17:15:44
 * @param <T>
 */
public class PageResult<T> {
	private Integer code;
	private Long count;
	private List<T> data;
	private String msg = "";

	public static <T> PageResult<T> success(Page<T> data) {
		PageResult<T> pageData = new PageResult<T>();
		pageData.setCode(DefaultResultCode.SUCCESS.getValue());
		pageData.setMsg(DefaultResultCode.SUCCESS.getMessage());
		pageData.setCount(data.getTotal());
		pageData.setData(data.getResult());
		return pageData;
	}


	public static <T> PageResult<T> of(ResultCode resultCode,Page<T> data) {
		PageResult<T> pageData = new PageResult<T>();
		pageData.setCode(resultCode.getValue());
		pageData.setMsg(resultCode.getMessage());
		pageData.setCount(data.getTotal());
		pageData.setData(data.getResult());
		return pageData;
	}

	public PageResult() {}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public Long getCount() {
		return count;
	}

	public void setCount(Long count) {
		this.count = count;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
